home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
cmdlg2
/
cmdialog.bas
next >
Wrap
BASIC Source File
|
1995-05-09
|
17KB
|
536 lines
Rem Demo for accessing Win 3.1 Common Dialogs
Rem Author: Costas Kitsos, CIS 73667,1755
Rem Revision: 1.00.00, July 4 1992
Rem Modified: L.J. Johnson, CIS 70700,1334
Rem Revision: 1.10.00, July 25 1992
DefInt A-Z
Declare Function lstrcpy Lib "Kernel" (ByVal lpDestString As Any, ByVal lpSourceString As Any) As Long
Function PColors% (MyForm As Form, CError&, Flags&)
MyForm.Cls
PColors% = 0: CError& = 0
Dim C As ChooseColor
Dim Address As Long
ReDim ClrArray(15) As Long ' Holds Custom Colors
wSize = Len(ClrArray(0)) * 16 ' Size of Memory Block
' ----------------------------------------------------
' A global block is allocated to hold a copy of the
' custom colors
' ----------------------------------------------------
MemHandle = GlobalAlloc(GHND, wSize)
If MemHandle = 0 Then
PColors% = 1
Exit Function
End If
Address = GlobalLock(MemHandle)
If Address = 0 Then
PColors% = 2
Exit Function
End If
' ----------------------------------------------------
' ----------------------------------------------------
' Fill Custom Colors with White
' ----------------------------------------------------
For i& = 0 To UBound(ClrArray)
ClrArray(i&) = &HFFFFFF
Next
' ----------------------------------------------------
' ----------------------------------------------------
'copy custom colors to the global block
' ----------------------------------------------------
Call hmemcpy(ByVal Address, ClrArray(0), wSize)
' ----------------------------------------------------
' ----------------------------------------------------
'get ready to call ChooseColor
' ----------------------------------------------------
C.lStructSize = Len(C)
C.hwndOwner = MyForm.hwnd
C.lpCustColors = Address
C.RgbResult = Dialogs.BackColor
C.Flags = Flags&
Result = ChooseColor(C)
CError& = CommDlgExtendedError()
If Result = 0 Then
PColors% = 3
Exit Function
End If
' ----------------------------------------------------
' ----------------------------------------------------
' copy the new custom colors locally
' ----------------------------------------------------
Call hmemcpy(ClrArray(0), ByVal Address, wSize)
OK = GlobalUnlock(MemHandle) 'Free The Memory
OK = GlobalFree(MemHandle)
' ----------------------------------------------------
' ----------------------------------------------------
' Select the new color for the background
' Comment this out if it's distracting
' Print the new custom colors
' ----------------------------------------------------
MyForm.BackColor = C.RgbResult
For i& = 0 To UBound(ClrArray)
MyForm.Print "Custom Color"; Str$(i&); ":", Hex$(ClrArray(i&))
Next
' ----------------------------------------------------
End Function
Function PFileOpen% (MyForm As Form, FError&, Filter$, IDir$, Title$, Index%, Flags&)
MyForm.Cls
PFileOpen% = 0: SaveError% = 0
Dim O As OPENFILENAME
Dim Address As Long
' ----------------------------------------------------
' First Copy the strings to the Global Memory Block
' Use a sub-allocation scheme to avoid overloading
' the LDT
' ----------------------------------------------------
szFile$ = String$(256, 0)
szFilter$ = Filter$
szInitialDir$ = IDir$
szTitle$ = Title$
wSize = Len(szFile$) + Len(szFilter$) + Len(szInitialDir$) + Len(szTitle$)
MemHandle = GlobalAlloc(GHND, wSize)
If MemHandle = 0 Then
PFileOpen% = 1
Exit Function
End If
' ----------------------------------------------------
' ----------------------------------------------------
' Lock global memory, then copy it to local memory
' ----------------------------------------------------
Address = GlobalLock(MemHandle)
If Address = 0 Then
PFileOpen% = 2
Exit Function
Else
Call hmemcpy(ByVal Address, ByVal (szFile$ + szFilter$ + szInitialDir$ + szTitle$), wSize)
End If
' ----------------------------------------------------
O.lStructSize = Len(O)
O.hwndOwner = MyForm.hwnd
O.Flags = Flags&
O.nFilterIndex = Index%
O.lpstrFile = Address
O.nMaxFile = Len(szFile$)
O.lpstrFilter = Address + Len(szFile$)
O.lpstrInitialDir = O.lpstrFilter + Len(szFilter$)
O.lpstrTitle = O.lpstrInitialDir + Len(szInitialDir$)
Result = GetOpenFileName(O)
FError& = CommDlgExtendedError()
If Result = 0 Then
PFileOpen% = 3
Else
Call hmemcpy(ByVal szFile$, ByVal Address, Len(szFile$))
End If
OK = GlobalUnlock(MemHandle) 'Free The Memory
OK = GlobalFree(MemHandle)
If Result = 0 Then Exit Function
File$ = Left$(szFile$, InStr(szFile$, Chr$(0)) - 1)
MyForm.Print "Common Dialogs File Open"
MyForm.Print
MyForm.Print "You selected:", File$
MyForm.Print "Path:", Left$(File$, O.nFileOffset)
MyForm.Print "Filename:", Right$(File$, Len(File$) - O.nFileOffset)
MyForm.Print "Extension:", Right$(File$, Len(File$) - O.nFileExtension)
End Function
Function PFileSave% (MyForm As Form, FError&, Filter$, IDir$, FileMask$, Index%, Title$, Flags&)
MyForm.Cls
PFileSave% = 0: FError& = 0
' This is similar to GetOpenFileName
Dim S As OPENFILENAME
Dim Address As Long
' ----------------------------------------------------
' First Copy the strings to the Global Memory Block
' Use a sub-allocation scheme to avoid wearing down
' the LDT
' ----------------------------------------------------
NoTitle$ = FileMask$
szFile$ = NoTitle$ + String$(256 - Len(NoTitle$), 0)
szFilter$ = Filter$
szInitialDir$ = IDir$
szTitle$ = Title$
wSize = Len(szFile$) + Len(szFilter$) + Len(szInitialDir$) + Len(szTitle$)
MemHandle = GlobalAlloc(GHND, wSize)
If MemHandle = 0 Then
PFileSave% = 1
Exit Function
End If
Address = GlobalLock(MemHandle)
If Address = 0 Then
PFileSave% = 2
Exit Function
Else
Call hmemcpy(ByVal Address, ByVal (szFile$ + szFilter$ + szInitialDir$ + szTitle$), wSize)
End If
S.lStructSize = Len(S)
S.hwndOwner = MyForm.hwnd
S.Flags = Flags&
S.nFilterIndex = Index%
S.lpstrFile = Address
S.nMaxFile = Len(szFile$)
S.lpstrFilter = Address + Len(szFile$)
S.lpstrInitialDir = S.lpstrFilter + Len(szFilter$)
S.lpstrTitle = S.lpstrInitialDir + Len(szInitialDir$)
Result = GetSaveFileName(S)
FError& = CommDlgExtendedError()
If Result = 0 Then
PFileSave% = 3
Exit Function
Else
Call hmemcpy(ByVal szFile$, ByVal Address, Len(szFile$))
End If
OK = GlobalUnlock(MemHandle) 'Free The Memory
OK = GlobalFree(MemHandle)
File$ = Left$(szFile$, InStr(szFile$, Chr$(0)) - 1)
MyForm.Print "Common Dialogs File Save"
MyForm.Print
MyForm.Print "You selected:", File$
MyForm.Print "Path:", Left$(File$, S.nFileOffset)
MyForm.Print "Filename:", Right$(File$, Len(File$) - S.nFileOffset)
MyForm.Print "Extension:", Right$(File$, Len(File$) - S.nFileExtension)
End Function
Function PFonts% (MyForm As Form, FError&, Flags&, FontType%)
MyForm.Cls
PFonts% = 0: FError& = 0
Dim A As ChooseFont
Dim F As LogFont
Dim Address As Long
' ----------------------------------------------------
' Save the defaults
' ----------------------------------------------------
OldFont$ = Dialogs.FontName
OldFontSize = Dialogs.FontSize
OldFontWeight = Dialogs.FontBold
OldFontItalic = Dialogs.FontItalic
OldFontStrikethru = Dialogs.FontStrikethru
OldFontUnderline = Dialogs.FontUnderline
OldFore